<?php $url = new Url();?>
<div class="left">
    <?php $this->widget("AdminQuanly")?>
</div>
<div class="right-main">
    <div class="righ-cont">
        <div class="right">
            <div class="title_style"> <span><b>Phân quyền cho admin : <?=$rowAdmin["username"] ?></b></span></div>

            <div class="table clearfix" style="width: 600px;">
                <table cellspacing="0" cellpadding="0" border="0" width="600px">
                    <tbody>
                        <tr class="bg_gray">
                            <td width="8%"><b>STT</b></td>
                            <td width="14%"><strong>Tên module</strong></td>
                            <td width="14%"><strong>Lựa chọn</strong></td>
                        </tr>
                        <?php 
                            $i = 1;
                            foreach(ConstantsUtil::$arr_module as $key=>$value){
                            ?>
                            <tr>
                                <td><?=$i++ ?></td>
                                <td><?=$value["label"] ?></td>
                                <td><input type="checkbox" name="permit" value="<?=$value["name"] ?>" <?= in_array($value["name"],$arr_item) ? 'checked="checked"':'' ?>></td>
                            </tr>
                            <?php }?>
                    </tbody>
                </table>
            </div>
            <div><button type="button" onclick="savePermit();">Lưu Phân Quyền</button></div>
        </div>
    </div>
</div>
<script type="text/javascript">
    function savePermit(){
        var user_id = '<?=$user_id ?>';
        var str_id = "";
        var item = $("input[name=permit]:checked");
        if(item.length==0){
            alert('Phải chọn ít nhất 1 bản ghi! ');
            return false;
        }
        item.each(function(){
            str_id += this.value + ',';     
        }); 
        var strUrl = '<?=$url->createUrl("admin/savePermit") ?>';
        $.ajax({
            type: "POST",
            url: strUrl,
            data: {
                user_id:user_id,
                str_id:str_id
            },
            success: function(msg){
                if(msg==1){
                    alert('Phân quyền thành công!');
                    window.location = '<?=$url->createUrl('admin/list') ?>';
                }else{
                    alert('Lỗi');
                }
            }
        });
    }
</script>